<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>对象解构</title>
</head>

<body>
  <script>
    const person = {
      name: 'John',
      age: 30,
    }
    //const { name, age } = { name: 'John', age: 30 };
    ////属性名和变量名必须一致
    //console.log(name); // John


    //对象解构的变量名可以更改
    const { name: firstName, age: personAge } = person;
    console.log(firstName); // John


    //数组对象的解构
    const p = [{
      name: 'John',
      age: 30,
    }, {
      name: 'Mary',
      age: 25,
    }]
    const [{ name, age }] = p;
    console.log(name); // John
    console.log(age); // 25
  </script>
</body>

</html>